#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <regex.h>
#include <unistd.h>
#include <string.h>

#include "regex_html.h"

/*$Id: extract.c 5 2012-10-26 04:17:18Z hymm91@gmail.com $*/


char * match( char *str, int len, char *retbuf, int *retlen)
{
	REGEX_HTML html;
	init_html_arg(&html, str, len, retbuf, *retlen);
	start_parse(&html);
	*retlen = html.result_len; 
	return retbuf;
}
int main(int argc, char **argv)
{
	char buf[40240];
	char retbuf[40240];
	int len, retlen;
	FILE *fp;
	if (argc < 2) {
		printf("usage: ./extract file.\n");
		exit(1);
	}

	fp = fopen(argv[1], "r");
	if (NULL == fp) {
		printf("can't open %s", argv[1]);
		exit(2);
	}
	while (fgets(buf, sizeof(buf), fp)) {
		retlen = 40240; 
		len = strlen((const char *)buf);
		match(buf, len, retbuf, &retlen);
		printf("%s", retbuf);
	}
	return 0;
}
/*$Id: extract.c 5 2012-10-26 04:17:18Z hymm91@gmail.com $*/
